package com.example.shoppinglist.dialogFragments;

import com.example.shoppinglist.R;
import com.example.shoppinglist.ScreenSlidePagerActivity;
import com.qustom.dialog.QustomDialogBuilder;
import android.app.AlertDialog;
import android.app.Dialog;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class ChangeColourDialogFragment extends DialogFragment{

	String selection = "";
	private AlertDialog dialog;
	String colour = "";

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		
		Drawable icon = getResources().getDrawable(R.drawable.ic_launcher);
		int color = ((ScreenSlidePagerActivity) getActivity()).getColor();
		
    	String[] options = new String[]{"Red", "Orange", "Yellow", "Green", "Blue", "Purple", "Pink"};
		ListView listy = new ListView(getActivity());
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, options);
		listy.setAdapter(adapter);
		listy.setOnItemClickListener(new OnItemClickListener() {
	
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int which,
					long arg3) {
				if(which == 0){
					selection = "Red";
					colour = "red";
					((ScreenSlidePagerActivity)getActivity()).changeColour(colour);
				}else if(which == 1){
					selection = "Orange";
					colour = "orange";
					((ScreenSlidePagerActivity)getActivity()).changeColour(colour);
				}else if(which == 2){
					selection = "Yellow";
					colour = "yellow";
					((ScreenSlidePagerActivity)getActivity()).changeColour(colour);
				}else if(which == 3){
					selection = "Green";
					colour = "green";
					((ScreenSlidePagerActivity)getActivity()).changeColour(colour);
				}else if(which == 4){
					selection = "Blue";
					colour = "blue";
					((ScreenSlidePagerActivity)getActivity()).changeColour(colour);
				}else if(which == 5){
					selection = "Purple";
					colour = "purple";
					((ScreenSlidePagerActivity)getActivity()).changeColour(colour);
				}else if(which == 6){
					selection = "Pink";
					colour = "pink";
					((ScreenSlidePagerActivity)getActivity()).changeColour(colour);
				}
				dialog.dismiss();
			}
		});
		
		dialog = new QustomDialogBuilder(getActivity())
		.setIcon(icon)
	    .setTitle("Trolley")
	    .setTitleColor(color)
	    .setDividerColor(color)
	    .setCustomView(listy)
	    .create();
		
	    return dialog;
	}
}
